package cn.edu.njust;

import cn.edu.njust.aio.AioEchoClient;
import cn.edu.njust.aio.AioEchoServer;
import cn.edu.njust.bio.BioEchoClient;
import cn.edu.njust.bio.BioEchoServer;
import cn.edu.njust.nio.NioEchoClient;
import cn.edu.njust.nio.NioEchoServer;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

@Slf4j
public class Main {

    @Test
    public void testBioServer() {

        EchoServer server = new BioEchoServer();

        server.listen(8000);
        server.serve();
    }

    @Test
    public void testBioClient() {

        for (int i = 0; i < 10; i++) {
            EchoClient client = new BioEchoClient();

            client.connect(8000);
            log.info("从服务器收到回应{}", client.echo("Hello Server"));
            client.close();
        }
    }

    @Test
    public void testNioServer() {

        EchoServer server = new NioEchoServer();

        server.listen(8000);
        server.serve();
    }

    @Test
    public void testNioClient() {

        for (int i = 0; i < 10; i++) {
            EchoClient client = new NioEchoClient();

            client.connect(8000);
            log.info("从服务器收到回应{}", client.echo("Hello Server"));
            client.close();
        }
    }

    @Test
    public void testAioServer() {

        EchoServer server = new AioEchoServer();

        server.listen(8000);
        server.serve();
    }

    @Test
    public void testAioClient() {

        for (int i = 0; i < 10; i++) {
            EchoClient client = new AioEchoClient();

            client.connect(8000);
            log.info("从服务器收到回应{}", client.echo("Hello Server"));
            client.close();
        }
    }
}
